package com.testng.oa.pub;

import java.util.Set;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class oalogin {
	private static WebElement element = null;
	public static WebElement login_UserName(WebDriver driver){
		element = driver.findElement(By.name("adminuser"));
		return element;
	}
	public static WebElement login_Password(WebDriver driver){
		element = driver.findElement(By.name("adminpass"));
		return element;
	}
	
	public static WebElement login_rempass(WebDriver driver){
		element = driver.findElement(By.name("rempass"));
		return element;
	}
	
	public static WebElement login_Button(WebDriver driver){
		element = driver.findElement(By.name("button"));
		return element;
	}
	public static WebElement login_GetWrongStr(WebDriver driver){
		element = driver.findElement(By.id("msgview"));
		return element;
	}
	
	public static WebElement login_GetLink(WebDriver driver, String linkText){
		element = driver.findElement(By.linkText(linkText));
		return element;
	}
	
	public static String openLink(WebDriver driver, String linkText, String handle){
		String url = "";
		login_GetLink(driver, linkText).click();
		Set<String> handles = driver.getWindowHandles();
		for (String handle1 : handles) {
			if (handle.equals(handle1) == false) {
				driver.switchTo().window(handle1);
				url=driver.getCurrentUrl();
				driver.close();
			}
		}
		return url;
		
	}
	
	public  static void oa_login(WebDriver driver, String username, String password) {
		login_UserName(driver).clear();
		login_UserName(driver).sendKeys(username);
		login_Password(driver).clear();
		login_Password(driver).sendKeys(password);
		login_Button(driver).click();
	}
}
